package com.crm.sys.tab;

import java.io.IOException;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

import org.springframework.web.servlet.tags.RequestContextAwareTag;

import com.google.common.base.Strings;
import com.crm.util.Constants;

public class EncryptionTag extends RequestContextAwareTag {
 
	/**
	 * 
	 */
	private static final long serialVersionUID = -6873153334580530006L;
	private String value;  //加密解密内容  
    private Integer type;  //类型  1 加密  2 解密
     
	public void setType(Integer type) {
		this.type = type;
	}

	public void setValue(String value) {
		this.value = value;
	}
 

	public EncryptionTag(){  
    
    }  
      
	@Override
	protected int doStartTagInternal() throws Exception {  
        JspWriter out = this.pageContext.getOut();  
        try {  
            if(type!=null&&type==2){
            	  out.print(Constants.CONTENT.decryptString(value));
            }else{
            	  out.print(Constants.CONTENT.encryptString(value));
            }
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
          
     //   System.out.println("对象正在处理开始标记.....");  
        return EVAL_BODY_INCLUDE;  
    }  
	
	/**
	 * 
	 * @param list
	 * @param value   默认值
	 * @return
	 * @throws Exception
	 */
	private String getSelectHtml(List<Integer> callinglist,String value) throws Exception{
		  StringBuffer  s = new StringBuffer();
		  if(Strings.isNullOrEmpty(value)){
			  value="-1";
		  }
		  for(Integer item:callinglist){
			  s.append("<option value='").append(item).append("' ").append(item==Integer.parseInt(value)?"selected >":">").append( Constants.CALLING.get(item+"")).append("</option>");
		  }
		 return s.toString();
	}
	
    public int doAfterBody() throws JspException{  
       // System.out.println("处理标签体（after body）....");  
        return SKIP_BODY;  
    }  
    public int doEndTag() throws JspException{  
      //  System.out.println("对象正在处理结束标记.....");  
        return EVAL_PAGE;  
    }  
}
